﻿Imports System.Data.SqlClient

Public Class clsE_Rendimiento
    Private mintIdRendimiento As Integer
    Private mintIdAutobus As Integer
    Private mstrNoEconomico As String
    Private mintIdOperador As Integer
    Private mstrNombreOperador As String
    Private mdatFecha As Date
    Private mintDia As Integer
    Private mintMes As Integer
    Private mintAnio As Integer
    Private mintIdDespacho As Integer
    Private mdblRendStd As Double
    Private mdblRendReal As Double
    Private mdblDiferencia As Double
    Public Property IdRendimiento() As Integer
        Get
            Return mintIdRendimiento
        End Get
        Set(ByVal value As Integer)
            mintIdRendimiento = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property

    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property NombreOperador() As String
        Get
            Return mstrNombreOperador
        End Get
        Set(ByVal value As String)
            mstrNombreOperador = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Dia() As Integer
        Get
            Return mintDia
        End Get
        Set(ByVal value As Integer)
            mintDia = value
        End Set
    End Property
    Public Property Mes() As Integer
        Get
            Return mintMes
        End Get
        Set(ByVal value As Integer)
            mintMes = value
        End Set
    End Property
    Public Property Anio() As Integer
        Get
            Return mintAnio
        End Get
        Set(ByVal value As Integer)
            mintAnio = value
        End Set
    End Property
    Public Property IdDespacho() As Integer
        Get
            Return mintIdDespacho
        End Get
        Set(ByVal value As Integer)
            mintIdDespacho = value
        End Set
    End Property
    Public Property RendStd() As Double
        Get
            Return mdblRendStd
        End Get
        Set(ByVal value As Double)
            mdblRendStd = value

        End Set
    End Property
    Public Property RendReal() As Double
        Get
            Return mdblRendReal
        End Get
        Set(ByVal value As Double)
            mdblRendReal = value

        End Set
    End Property
    Public Property Diferencia() As Double
        Get
            Return mdblDiferencia
        End Get
        Set(ByVal value As Double)
            mdblDiferencia = value

        End Set
    End Property
    Public Sub New()
        mintIdDespacho = 0
        mintIdAutobus = 0
        mstrNoEconomico = ""
        mintIdOperador = 0
        mstrNombreOperador = ""
        mdatFecha = Now()
        mintDia = 0
        mintMes = 0
        mintAnio = 0
        mintIdDespacho = 0
        mdblRendStd = 0
        mdblRendReal = 0
        mdblDiferencia = 0

    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into E_Rendimiento (" & _
                            "IdAutobus," & _
                            "NoEconomico," & _
                            "IdOperador," & _
                            "NombreOperador," & _
                            "Fecha," & _
                            "Dia," & _
                            "Mes," & _
                            "Anio," & _
                            "IdDespacho," & _
                            "RendStd," & _
                            "RendReal," & _
                            "Diferencia) " & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "substring(@NoEconomico,1,100)," & _
                            "@IdOperador," & _
                            "substring(@NombreOperador,1,150)," & _
                            "@Fecha," & _
                            "@Dia," & _
                            "@Mes," & _
                            "@Anio," & _
                            "@IdDespacho," & _
                            "@RendStd," & _
                            "@RendReal," & _
                            "@Diferencia) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("IdDespacho", mintIdDespacho)
        Command.Parameters.AddWithValue("RendStd", mdblRendStd)
        Command.Parameters.AddWithValue("RendReal", mdblRendReal)
        Command.Parameters.AddWithValue("Diferencia", mdblDiferencia)
        

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de rendimiento", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update E_Rendimiento Set " & _
                            "IdAutobus=@IdAutobus," & _
                            "NoEconomico=substring(@NoEconomico,1,50)," & _
                            "IdOperador=@IdOperador," & _
                            "NombreOperador=substring(@NombreOperador,1,50)," & _
                            "Fecha=@Fecha," & _
                            "Dia=@Dia," & _
                            "Mes=@Mes," & _
                            "Anio=@Anio," & _
                            "IdDespacho=@IdDespacho," & _
                            "RendStd=@RendStd," & _
                            "RendReal=@RendReal," & _
                            "Diferencia=@Diferencia " & _
                            " Where IdRendimiento=@IdRendimiento"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdRendimiento", mintIdRendimiento)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("IdDespacho", mintIdDespacho)
        Command.Parameters.AddWithValue("RendStd", mdblRendStd)
        Command.Parameters.AddWithValue("RendReal", mdblRendReal)
        Command.Parameters.AddWithValue("Diferencia", mdblDiferencia)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro de rendimiento", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
